package com.rou.im.framework.boot.starter;

import com.rou.im.framework.boot.starter.builder.ProcessorStackBuilder;
import com.rou.im.framework.boot.starter.postprocessor.ObjectPostProcessor;
import com.rou.im.framework.boot.starter.postprocessor.ObjectPostProcessorConfiguration;
import com.rou.im.framework.boot.starter.postprocessor.ProcessorStackConfigurerAdapter;
import com.rou.im.framework.core.processorstack.ProcessorStack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * <p>
 *     数据结构就是 多个栈
 *    一个ProcessorStack
 * </p>
 *
 * @author GaoShuangWen
 * @since 2020-05-05 15:44
 */
@Configuration
@Import(ObjectPostProcessorConfiguration.class)
public class ProcessorStackAutoConfiguration {
    private ObjectPostProcessor<Object> objectPostProcessor;

    @Autowired
    ProcessorStackConfigurerAdapter processorStackConfigurerAdapter;
    @Autowired
    public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) {
        this.objectPostProcessor = objectPostProcessor;
    }

    @Bean(name ="processorStack")
    public ProcessorStack processorStack() throws Exception {
        ProcessorStackBuilder builder = objectPostProcessor
                .postProcess(new ProcessorStackBuilder(objectPostProcessor,processorStackConfigurerAdapter));
        return builder.build();
    }

}
